/* Copyright (c) 2016-2020 Enfry Ltd. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of Enfry. 
 * You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with Enfry.
 */
package com.enfry.common.util.array;

import java.util.Collection;
import java.util.Iterator;

import com.enfry.common.util.annotation.AnAlias;

/**
 * 
 * <请简单说明此类用途>
 * 
 * @Title com.enfry.util.Listx
 * @author Penghu
 * @date 2018年1月10日
 */
@AnAlias("Collectionx")
public class Collectionx extends Iterablex {
	// Query Operations

	public static int size(Collection<?> collection) {
		return (collection == null) ? 0 : collection.size();
	}

	public static boolean isEmpty(Collection<?> collection) {
		return (collection == null) ? true : collection.isEmpty();
	}

	public static <E> boolean contains(Collection<E> collection, Object o) {
		return (collection == null) ? false : collection.contains(o);
	}

	public static <E> Iterator<E> iterator(Collection<E> collection) {
		return collection.iterator();
	}

	public static Object[] toArray(Collection<?> collection) {
		return collection.toArray();
	}

	public static <T> T[] toArray(Collection<?> collection, T[] a) {
		return collection.toArray(a);
	}

	// Modification Operations

	public static <E> boolean add(Collection<E> collection, E e) {
		return (collection == null) ? false : collection.add(e);
	}

	public static boolean remove(Collection<?> collection, Object o) {
		return (collection == null) ? false : collection.remove(o);
	}

	// Bulk Operations

	public static <E> boolean containsAll(Collection<E> collection, Collection<?> c) {
		return (collection == null) ? false : collection.containsAll(c);
	}

	public static <E> boolean addAll(Collection<E> collection, Collection<? extends E> c) {
		return (collection == null) ? false : collection.addAll(c);
	}

	public static boolean removeAll(Collection<?> collection) {
		return (collection == null) ? false : collection.removeAll(collection);
	}

	public static boolean retainAll(Collection<?> collection, Collection<?> c) {
		return (collection == null) ? false : collection.retainAll(c);
	}

	public static void clear(Collection<?> collection) {
		if (collection == null)
			return;

		collection.clear();
	}

	// Comparison and hashing

	public static boolean equals(Collection<?> collection, Object o) {
		return (collection == null) ? (o == null) : collection.equals(o);
	}

	public static int hashCode(Collection<?> collection) {
		return (collection == null) ? 0 : collection.hashCode();
	}
}
